<include file="./Template/Admin/header.html" title="权限分配" />

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <form action="{:U('Admin/Group/rule')}" method="post" id="forma">
        <input type="hidden" name="id" value="{$id}">
        <div class="col-sm-13">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <div class="row m-b-sm m-t-sm">
                        <div class="col-md-2">
                            <a href="{:U('Admin/Group/index')}" class="btn btn-outline btn-primary">返回分组列表</a>
                        </div>
                    </div>
                    <div class="hr-line-dashed"></div>

                    <foreach name="ruleInfo" item="v1" >
                    <div class="row levelOne">
                        <label class="checkbox-inline"><input type="checkbox" name="ruleIds[]" value="{$v1['id']}" onclick="checkOne(this)" <if condition="in_array($v1['id'],$rules)">checked</if> /><h4 style="margin-top: -3px">{$v1['title']}</h4></label>
                        <div class="hr-line-dashed" style="margin-top: -4px;margin-bottom: 6px;"></div>

                        <notempty name="v1['_child']">
                            <foreach name="v1['_child']" item="v2" >
                                <?php $arrNum = count($v2['_child'])?><!--子元素数量-->
                                <div class="col-sm-{$arrNum+2} levelTwo" style="padding-left: 0px;font-size: 12px;">
                                <table class="table table-striped table-bordered table-hover table-condensed tmar">
                                    <tr class="b-group">
                                        <th width="23%"><label>&nbsp;&nbsp;&nbsp;&nbsp;{$v2['title']} <input type="checkbox" name="ruleIds[]" value="{$v2['id']}" onclick="checkTwo(this)" <if condition="in_array($v2['id'],$rules)">checked</if>></label></th>

                                        <notempty name="v2['_child']">
                                        <td class="levelThree">
                                            <foreach name="v2['_child']" item="v3" >
                                                <label>&nbsp;&nbsp;{$v3['title']}&nbsp;&nbsp;<input type="checkbox" name="ruleIds[]" value="{$v3['id']}" onclick="checkThree(this)" <if condition="in_array($v3['id'],$rules)">checked</if> /></label>
                                            </foreach>
                                        </td>
                                        </notempty>

                                    </tr>
                                </table>
                            </div>

                            </foreach>
                        </notempty>

                    </div>
                    </foreach>

                    <input type="submit" id="submit" name="submit" value="提交" class="btnsub">
                </div>
            </div>
        </div>

    </form>
</div>
<script src="__ADMIN__js/jquery.min.js"></script>
<script src="__ADMIN__js/bootstrap.min.js"></script>
<script src="__ADMIN__js/plugins/layer.3/layer.js"></script>
<script src="__ADMIN__js/common.js"></script>
<script>
    $(function(){
        $('#submit').click(function () {
            var forma = new FormData (document.getElementById('forma'));
            $.ajax({
                url:$('#forma').prop('action'),
                type:'post',
                data:forma,
                dataType:'json',
                processData: false,
                contentType: false,
                success:function(data){
                    if(data.status > 0){
                        common.error(data.msg);
                    }else{
                        common.success(data.msg,"{:U('Group/rule?id='.$id)}");
                    }
                }
            });
            return false;
        });
    });
    function checkOne(obj){
        $(obj).parents('.levelOne').eq(0).find("input[type='checkbox']").prop('checked',$(obj).prop('checked'));
    }
    function checkTwo(obj){
        $(obj).parents('.levelTwo').eq(0).find("input[type='checkbox']").prop('checked',$(obj).prop('checked'));
    }
    function checkThree(obj){

    }
</script>
</body>
</html>
